/*===============================================*/
/*================= RESTAT MS24757 ==============*/
/*============== F.Cumming & P.Hubert ===========*/
/*============== Time series analysis ===========*/
/*===============================================*/

drop _all
clear matrix
global DIR "C:\XXX"
cd "${DIR}"

use "RESTAT_MS24757_Macro_data.dta", clear 
tsset date

//---- Merge with Regional data
merge 1:1 date using "Reg_Statevar.dta"
drop if _merge==2
drop _merge
rename *lti* *li*

//----- Axis variables
gen zero = 0
gen xaxis = 0 if _n==1
replace xaxis = xaxis[_n-1]+1 if _n>1
replace xaxis = . if _n>19

//--- Labels
label variable cpi "Consumer price inflation"
label variable ndur_c_m "Non-durable cons."
label variable dur_c_m "Durable cons."
label variable ser_c_m "Services"
label variable tot_c_m "Total consumption"
label variable indpro "Industrial production"
label variable emp_yoy "Employment"
label variable unemp "Unemployment" 
label variable sterling "Sterling exch. rate"
label variable ftse "FTSE prices"
label variable clendn "Net consumer lending"
label variable gdp_m "Real GDP growth"
label variable li_95 "Raw-LTI>p(95)"
label variable li_adj_75 "LTI>p(75)"
label variable li_adj_90 "LTI>p(90)"
label variable li_adj_95 "LTI>p(95)"
label variable li_adj_975 "LTI>p(97.5)"
label variable li_adj_poor "LTI>p(95) & Income<p(75)"
label variable li_adj_lv75 "LTI>p(95) & LTV>75"
label variable li_adj_old "LTI>p(95) & Age>p(50)"
label variable li_adj_exl "LTI>p(95) & Excl. L&SE"
label variable li_fit_95 "CF-trend-corr LTI>p(95)"
label variable li_adj_levn "LTI>p(95) & Level-NoPCincome"
label variable li_adj_logy "LTI>p(95) & Log-PCincome"
label variable li_adj_logn "LTI>p(95) & Log-NoPCincome"
label variable lv_adj_95 "LTV>p(95)" 
label variable pti_adj_95 "PTI>p(95)"
label variable li_adj_ex_lv "LTV"
label variable li_adj_ex_pti "PTI"

* share of variable rate
gen mst_fl_sh = mst_fl / mst_all * 100 

/*====================================================*/
/*=========== Identifying Monetary Shocks  ===========*/
/*====================================================*/

cap drop *_shock

//----- Monetary shocks
eststo : reg D.r_2y L.r_2y ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y
predict r_2y_shock, residuals
label variable r_2y_shock
//
esttab est1 using TabC1.rtf, b(3) se(2) br noeqlines nogaps nolines ///
star(* 0.1 ** 0.05 *** 0.01) depvars order() stats(N r2) replace
eststo clear
//
reg D.r_2y L.r_2y ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y 
estat dwatson
lincom "D.cbm_cpi_4 + D.cbm_cpi_8 + D.cbm_cpi_12"
lincom "D.cbm_gdp_4 + D.cbm_gdp_8 + D.cbm_gdp_12"
//
reg r_2y_shock L(1/3).r_2y_shock
lincom "L1.r_2y_shock + L2.r_2y_shock + L3.r_2y_shock"

//---- Shadow rate (Krippner) shock
reg D.krip L.krip ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y
eststo
predict krip_shock, residuals
label variable krip_shock

//---- Bank rate shock
local variable boe_r
foreach var of local variable {
reg D.`var' L.`var' ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y if date<tm(2009m4)
predict `var'_shock if date<tm(2009m4), residuals
label variable `var'_shock
}

//--- Sum MP shock
cap drop *_shsum
local variable r_2y krip boe_r
foreach var of local variable {
gen `var'_shsum = 0
replace `var'_shsum = `var'_shock + L.`var'_shsum if `var'_shock!=.
replace `var'_shsum = . if `var'_shock==.
}


//--- Validity of monetary shocks
local variable r_2y krip  
foreach var of local variable {
reg `var'_shock L(1/6).cpi L(1/6).indpro L(1/6).oil L(1/6).sterling L(1/6).netlending L(1/6).hp 
}

/*======================================================================*/
/*============= Loan-level Exogenous State-variables ===================*/
/*======================================================================*/

//----- Smoothing 
cap drop s_*
local variable li_adj_75 li_adj_90 li_adj_95 li_adj_975 ///
li_adj_ex_lv li_adj_ex_pti ///
li_adj_poor li_adj_lv75 li_adj_old li_adj_exl ///
li_adj_mean li_adj_med lv_adj pti_adj ///
li_adj_levn li_adj_logy li_adj_logn
foreach var of local variable {
tssmooth ma s_`var' = `var', window(2 1 2) replace
label variable s_`var'
}

//----- Trend/cycle decomposition of fitted values: minperiod(18)=1.5y / maxperiod(96)=8y
cap drop c*_li_fit_*
local variable li_fit_95
foreach var of local variable {
tsfilter cf c6_`var' = `var', minperiod(6) 
label variable c6_`var'
tsfilter cf c18_`var' = `var', minperiod(18)   
label variable c18_`var'
}

//--- State-variable plot
cap drop li_adj_95_100 
cap drop c6_li_fit_95_100
gen li_adj_95_100 = li_adj_95*100
gen c6_li_fit_95_100 = c6_li_fit_95*100
//
cap drop li_p95_*_100
forvalues i = 1(1)12 {
gen li_p95_`i'_100 = li_p95_`i'*100
}

/*===========================================================*/
/*========================== Figure B1 ======================*/
/*===========================================================*/

//--- Mean Loan
replace loan = loan*1000
twoway (connected loan date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) ///
(connected loan date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) if loan!=., ///
xsize(4) ysize(2) scale(1.3) aspectratio(0.33) ///
xtitle("") xlabel(540(24)691, format(%tmCCYY) labsize(medsmall)) ///
ylabel(#5, angle(horiz) axis(1)) ytitle("Hundreds £", axis(1)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ///
ifcolor(white) ilcolor(white)) plotregion(lcolor(black)) legend(cols(1) size(medium) symysize(*.3) symxsize(*.3) rowgap(*.3) ///
ring(0) position(5) order(1 "Mean Loan per month"))
graph export FigB1a.png, width(3000) height(1500) replace

//--- Mean LTI
twoway (connected li date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) ///
(connected li date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) if li!=., ///
xsize(4) ysize(2) scale(1.3) aspectratio(0.33) ///
xtitle("") xlabel(540(24)691, format(%tmCCYY) labsize(medsmall)) ///
ylabel(#4, angle(horiz) axis(1)) ytitle("Ratio", axis(1)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ///
ifcolor(white) ilcolor(white)) plotregion(lcolor(black)) legend(cols(1) size(medium) symysize(*.3) symxsize(*.3) rowgap(*.3) ///
ring(0) position(5) order(1 "Mean LTI per month"))
graph export FigB1b.png, width(3000) height(1500) replace

//--- Share of Raw LTI_p95
cap drop li_95_100
gen li_95_100 = li_95*100
sum li_95_100
twoway (connected li_95_100 date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) ///
(connected li_95_100 date, lcolor(black) mcolor(black) msymbol(circle) msize(medlarge) mfcolor(none)) if li_95_100!=., ///
xsize(4) ysize(2) scale(1.3) aspectratio(0.33) ///
xtitle("") xlabel(540(24)691, format(%tmCCYY) labsize(medsmall)) ///
ylabel(2(2)8, angle(horiz) axis(1)) ytitle("Per cent", axis(1)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ///
ifcolor(white) ilcolor(white)) plotregion(lcolor(black)) legend(cols(1) size(medium) symysize(*.3) symxsize(*.3) rowgap(*.3) ///
ring(0) position(5) order(1 "Share of mortgages with Raw-LTI>p(95) per month"))
graph export FigB1c.png, width(3000) height(1500) replace


/*=========================================================*/
/*====================== Figure B2 ========================*/
/*=========================================================*/

corr s_li_adj_95 r_2y_shock
corr s_li_adj_95 S3.clendn

//---- MP shock & LTI>p(95) state variable
twoway (lfitci r_2y_shock s_li_adj_95, clcolor(black) clwidth(medthin) level(99)) ///
(scatter r_2y_shock s_li_adj_95, color(navy) msymbol(o)), ///
title("Monetary Policy", size(medium) color(black)) xtitle("") ///
ylabel(-0.5(0.25)0.75, angle(horizontal) labsize(medium)) ///
xlabel(0.03(0.01)0.08, angle(horizontal) labsize(medium)) ///
aspectratio(1) ytitle("MP shock") yscale(titlegap(*0.1)) ///
xtitle("LTI>p(95) state-variable")  xscale(titlegap(*3)) legend(cols(1) order(2 "{&rho}=0.06") ///
symysize(6) symxsize(6) size(medium) rowgap(*.01) colgap(*.01) ring(0) position(11)) ///
graphregion(fcolor(white) lcolor(white)) name(corr_r_2y_shock, replace) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white))

//---- Consumer lending & LTI>p(95) state variable
twoway (lfitci S3.clendn s_li_adj_95, clcolor(black) clwidth(medthin) level(99)) ///
(scatter S3.clendn s_li_adj_95, color(navy) msymbol(o)), ///
title("Consumer lending growth", size(medium) color(black)) xtitle("") ///
ylabel(#4, angle(horizontal) labsize(medium)) ///
xlabel(0.03(0.01)0.08, angle(horizontal) labsize(medium)) ///
aspectratio(1) ytitle("Consumer lending growth") yscale(titlegap(*0.1)) ///
xtitle("LTI>p(95) state-variable")  xscale(titlegap(*3)) legend(cols(1) order(2 "{&rho}=-0.01") ///
symysize(6) symxsize(6) size(medium) rowgap(*.01) colgap(*.01) ring(0) position(5)) ///
graphregion(fcolor(white) lcolor(white)) name(corr_clendn, replace) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white))

graph combine corr_r_2y_shock corr_clendn, ///
rows(1) cols(2) imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.3) xsize(2) ysize(1) 
graph export FigB2.png, width(2000) height(1000) replace


/*===========================================================*/
/*========================== Figure C1 ======================*/
/*===========================================================*/

cap gen shock_bp = r_2y_shock * 100
twoway (connected shock_bp date, lcolor(black) mcolor(black) msymbol(circle) mfcolor(none)) if shock_bp!=., ///
title("", size(medium)) xtitle("") ///
xlabel(540(24)691, format(%tmCCYY) labsize(medium)) yline(0) xsize(4) ysize(2) scale(1.3) aspectratio(0.33)  ///
ylabel(-75(25)75, angle(horiz) axis(1)) ytitle("Basis points", axis(1)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ///
ifcolor(white) ilcolor(white)) plotregion(lcolor(black)) legend(cols(1) size(medium) symysize(*.3) symxsize(*.3) rowgap(*.3) ///
ring(0) position(5) order(1 "Monetary shock ϵ{superscript:i}{subscript:t}")) 
graph export FigC1.png, width(3000) height(1500) replace


/*===========================================================*/
/*========================== Figure D1 ======================*/
/*===========================================================*/

//------ FigD1 ------// 
local statevar li_adj_mean li_adj_med lv_adj
foreach stvar of local statevar {
gen c_`stvar' = `stvar'
}
cap drop h_*med* l_*med*
local cyclevar c
local statevar li_adj_mean li_adj_med lv_adj
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_med_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_med_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
//FigD1a
local cyclevar c
local statevar li_adj_mean
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_1 h_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_2 h_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_1 l_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_2 l_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14,  ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High metric" 7 "Low metric") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on 
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigD1a.png, width(1000) height(1000) replace
}
}
//FigD1b
local cyclevar c
local statevar li_adj_med
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_1 h_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_2 h_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_1 l_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_2 l_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14,  ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High metric" 7 "Low metric") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on 
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigD1b.png, width(1000) height(1000) replace
}
}
//FigD1c
local cyclevar c
local statevar lv_adj
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_1 h_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_2 h_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_1 l_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_2 l_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14,  ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High metric" 7 "Low metric") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on 
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigD1c.png, width(1000) height(1000) replace
}
}

//------ FigD1d ------// 
cap drop c_li
tsfilter cf c_li = li, minperiod(2) 
cap drop h_*mean* l_*mean*
local cyclevar c
local statevar li
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_mean_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_mean_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar c
local statevar li
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_mean_`var'_1 l_`cyvar'_`stvar'_mean_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_mean_`var'_2 l_`cyvar'_`stvar'_mean_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_mean_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea h_`cyvar'_`stvar'_mean_`var'_1 h_`cyvar'_`stvar'_mean_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_mean_`var'_2 h_`cyvar'_`stvar'_mean_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_mean_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High mean LTI" 4 "Low mean LTI") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
}
}
graph export FigD1d.png, width(1000) height(1000) replace

//------ FigD1e ------// 
cap drop c_med_li_ym
tsfilter cf c_med_li_ym = med_li_ym, minperiod(2) 
cap drop h_*med* l_*med*
local cyclevar c
local statevar med_li_ym
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_med_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_med_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar c
local statevar med_li_ym
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_1 l_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_med_`var'_2 l_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_1 h_`cyvar'_`stvar'_med_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_med_`var'_2 h_`cyvar'_`stvar'_med_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_med_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High median LTI" 4 "Low median LTI") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
}
}
graph export FigD1e.png, width(1000) height(1000) replace

//------ FigD1f ------// 
cap drop c_lv
tsfilter cf c_lv = lv, minperiod(2) 
cap drop h_*ltv* l_*ltv*
local cyclevar c
local statevar lv
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_ltv_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_ltv_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar c
local statevar lv
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_ltv_`var'_1 l_`cyvar'_`stvar'_ltv_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_ltv_`var'_2 l_`cyvar'_`stvar'_ltv_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_ltv_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea h_`cyvar'_`stvar'_ltv_`var'_1 h_`cyvar'_`stvar'_ltv_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_ltv_`var'_2 h_`cyvar'_`stvar'_ltv_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_ltv_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High mean LTV" 4 "Low mean LTV") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
}
}
graph export FigD1f.png, width(1000) height(1000) replace


/*====================================================*/
/*===================== Figure E1 ====================*/
/*====================================================*/

//------ FigE1a ------// 
tssmooth ma indpro = indpro, window(3 1 3) replace
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls') c.indpro##c.`mpshock', vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigE1a.png, width(1000) height(1000) replace
}
}
//------ FigE1b ------//
cap drop s2_li_adj_95
local covariates gdp_m unemp hp D.ftsev
reg s_li_adj_95 L(0/12).(`covariates')
predict s2_li_adj_95, residuals 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s2
local statevar li_adj_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar s2
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t} residuals" 7 "Low S{subscript:t} residuals") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigE1b.png, width(1000) height(1000) replace
}
}
//------ FigE1c ------// 
cap drop h_*pcr* l_*pcr*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls') if (date<tm(2008m07)|date>tm(2009m06)), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_pcr_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_pcr_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar s
local statevar li_adj_95
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_pcr_`var'_1 l_`cyvar'_`stvar'_pcr_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_pcr_`var'_2 l_`cyvar'_`stvar'_pcr_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_pcr_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_pcr_`var'_1 h_`cyvar'_`stvar'_pcr_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_pcr_`var'_2 h_`cyvar'_`stvar'_pcr_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_pcr_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigE1c.png, width(1000) height(1000) replace
}
}



/*=========================================*/
/*=============== Figure E2 ===============*/
/*=========================================*/

//------ FigE2a ------// 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls') c.uk_epu##c.`mpshock', vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigE2a.png, width(1000) height(1000) replace
}
}

//------ FigE2b ------// 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls') c.uk_3m12m##c.`mpshock', vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigE2b.png, width(1000) height(1000) replace
}
}

/*====================================================================*/
/*============================= Figure F1 ============================*/
/*====================================================================*/

//------ FigF1a ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_ex_lv
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_ex_lv
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t} w/o `v2text'" 4 "Low S{subscript:t} w/o `v2text'") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.2) xsize(1) ysize(1) 
graph export FigF1a.png, width(1000) height(1000) replace
}
}

//------ FigF1b ------// 
cap drop s_lv_adj_95
tssmooth ma s_lv_adj_95 = lv_adj_95, window(2 1 2) replace 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar lv_adj_95
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar lv_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on  // grc1leg
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigF1b.png, width(1000) height(1000) replace
}
}

/*================================================================*/
/*========================= Figure G1 ============================*/
/*================================================================*/

//------ FigG1 ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_logn li_adj_levn li_adj_logy
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
//FigG1a
local cyclevar s
local statevar li_adj_logn
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG1a.png, width(1000) height(1000) replace
}
}
//FigG1b
local cyclevar s
local statevar li_adj_levn
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG1b.png, width(1000) height(1000) replace
}
}
//FigG1c
local cyclevar s
local statevar li_adj_logy
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG1c.png, width(1000) height(1000) replace
}
}

/*=====================================================================*/
/*============================== Figure G2 ============================*/
/*=====================================================================*/

//------ FigG2 ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable ser_c_m ndur_c_m dur_c_m                        
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95 
local variable ser_c_m ndur_c_m dur_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-6(3)3, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_ser_c_m `cyvar'_`stvar'_ndur_c_m `cyvar'_`stvar'_dur_c_m , ///
rows(1) cols(3) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.5) xsize(3) ysize(1)
}
}
graph export FigG2.png, width(3000) height(1000) replace

/*=====================================================================*/
/*============================== Figure G3 ============================*/
/*=====================================================================*/

//------ FigG3 ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_95 
local variable gdp_m                             
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95 
local variable gdp_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`var'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_gdp_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1)
}
}
graph export FigG3.png, width(1000) height(1000) replace

/*================================================================*/
/*========================= Figure G4 ============================*/
/*================================================================*/

//------ FigG4 ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_75 li_adj_90 li_adj_975
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
//FigG4a
local cyclevar s
local statevar li_adj_75
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG4a.png, width(1000) height(1000) replace
}
}
//FigG4b
local cyclevar s
local statevar li_adj_90
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG4b.png, width(1000) height(1000) replace
}
}
//FigG4c
local cyclevar s
local statevar li_adj_975
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG4c.png, width(1000) height(1000) replace
}
}


/*================================================================*/
/*========================= Figure G5 ============================*/
/*================================================================*/

//------ FigG5 ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_poor li_adj_old li_adj_lv75 li_adj_exl
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
//FigG5a
local cyclevar s
local statevar li_adj_poor
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG5a.png, width(1000) height(1000) replace
}
}
//FigG5b
local cyclevar s
local statevar li_adj_old
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG5b.png, width(1000) height(1000) replace
}
}
//FigG5c
local cyclevar s
local statevar li_adj_lv75
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG5c.png, width(1000) height(1000) replace
}
}
//FigG5d
local cyclevar s
local statevar li_adj_exl
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG5d.png, width(1000) height(1000) replace
}
}


/*===========================================================*/
/*====================== Figure G6 ==========================*/
/*===========================================================*/

tssmooth ma r_2y_shsum2 = r_2y_shsum, window(1 1 1) replace
cap drop exp
gen exp = 0
replace exp = 1 if S1.r_2y_shsum2<0
cap drop res
gen res = 0
replace res = 1 if S1.r_2y_shsum2>0 & S1.r_2y_shsum2!=.

//------ FigG6a: LP res ------// 
cap drop h_*res* l_*res*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                          
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock'##c.exp) c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_res_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_res_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_res_`var'_1 h_`cyvar'_`stvar'_res_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_res_`var'_2 h_`cyvar'_`stvar'_res_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_res_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_res_`var'_1 l_`cyvar'_`stvar'_res_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_res_`var'_2 l_`cyvar'_`stvar'_res_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_res_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-6(3)6, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(res, replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t} + Res. MP" 7 "Low S{subscript:t} + Res. MP") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
}
}
//------ FigG6b: LP exp ------// 
cap drop h_*exp* l_*exp*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                          
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock'##c.res) c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "-`mpshock' - ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "-`mpshock' - ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_exp_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_exp_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_exp_`var'_1 h_`cyvar'_`stvar'_exp_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_exp_`var'_2 h_`cyvar'_`stvar'_exp_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_exp_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_exp_`var'_1 l_`cyvar'_`stvar'_exp_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_exp_`var'_2 l_`cyvar'_`stvar'_exp_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_exp_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-6(3)6, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(exp, replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t} + Exp. MP" 7 "Low S{subscript:t} + Exp. MP") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
}
}
set graphics on
graph combine res exp, ///
rows(1) cols(2) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.4) xsize(2) ysize(1) 
graph export FigG6.png, width(2000) height(1000) replace


/*===================================================================*/
/*===========================  Figure G7  ===========================*/
/*===================================================================*/

/*======= Bank rate shocks before 2009m4: small sample =====*/
cap drop br_shock 
gen br_shock = boe_r_shsum
label variable br_shock "Bank rate shocks"
//
cap drop h_*br_shock* l_*br_shock*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
local mpvar br_shock
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach mpshock of local mpvar {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local controls L1.`var' emp_yoy mfw_all clendn mfw_sh_fl D.mst_fl_sh
quiet reg `lead'.`var' c.`cyvar'_`stvar'##c.`mpshock' c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
local mpvar br_shock
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach mpshock of local mpvar {
foreach var of local variable {
local vtext : variable label `mpshock' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_1 h_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_2 h_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_1 l_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_2 l_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(#4, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`mpshock', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
}
}
}

/*===============  Intraday-IV Bank Rate Shocks =============*/
cap drop ma16_exp
gen ma16_exp = 0
replace ma16_exp = ma16_mps if ma16_mps<0
cap drop ma16_res
gen ma16_res = 0
replace ma16_res = ma16_mps if ma16_mps>0
//
cap drop br_fit 
quiet reg S1.boe_r ma16_exp ma16_res if date<tm(2015m1)
predict br_fit, xb
label variable br_fit "Intraday-IV shocks"
//
cap drop h_*br_fit* l_*br_fit*    
local cyclevar s
local statevar li_adj_95
local variable tot_c_m   
local mpvar br_fit
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach mpshock of local mpvar {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym
quiet reg `lead'.`var' c.`cyvar'_`stvar'##c.`mpshock' c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m 
local mpvar br_fit
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach mpshock of local mpvar {
foreach var of local variable {
local vtext : variable label `mpshock' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_1 h_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_2 h_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_1 l_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_2 l_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(#4, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`mpshock', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
}
}
}

/*========== Krippner Shocks ========*/
cap drop kp
gen kp = krip_shsum
label variable kp "Krippner shocks"
//
cap drop h_*kp* l_*kp* 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m   
local mpvar kp
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach mpshock of local mpvar {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_`mpshock'_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m 
local mpvar kp
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach mpshock of local mpvar {
foreach var of local variable {
local vtext : variable label `mpshock' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_1 h_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_`mpshock'_`var'_2 h_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_1 l_`cyvar'_`stvar'_`mpshock'_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_`mpshock'_`var'_2 l_`cyvar'_`stvar'_`mpshock'_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_`mpshock'_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`mpshock', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}" 7 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(7)) aspectratio(0.9) 
}
}
}
}
//
set graphics on 
graph combine br_shock br_fit kp, ///
rows(1) cols(3) imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.5) xsize(3) ysize(1) 
graph export FigG7.png, width(3000) height(1000) replace


/*==========================================================*/
/*========================== Figure G8 =====================*/
/*==========================================================*/

//------ FigG8a ------// 
cap drop c_mfw_all
tsfilter cf c_mfw_all = mfw_all, minperiod(2) 
cap drop h_*mfw* l_*mfw*
local cyclevar c
local statevar mfw_all
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_mfw_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_mfw_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar c
local statevar mfw_all
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_mfw_`var'_1 h_`cyvar'_`stvar'_mfw_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_mfw_`var'_2 h_`cyvar'_`stvar'_mfw_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_mfw_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea l_`cyvar'_`stvar'_mfw_`var'_1 l_`cyvar'_`stvar'_mfw_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_mfw_`var'_2 l_`cyvar'_`stvar'_mfw_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_mfw_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High mortg. flows" 7 "Low mortg. flows") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on  
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.2) xsize(1) ysize(1) 
}
}
graph export FigG8a.png, width(1000) height(1000) replace

//------ FigG8b ------//
cap drop csplit
gen csplit = 0
replace csplit = 1 if date>=tm(2008m8)
//
cap drop h_csplit_* l_csplit_*
local variable tot_c_m
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach var of local variable {
foreach lead of local forward {
local mpshock r_2y_shsum
local controls L1.`var' emp_yoy mfw_all clendn mfw_sh_fl D.mst_fl_sh remortg hp r mort_dur iqr_li_ym
quiet reg `lead'.`var' L(0/1).(c.csplit##c.`mpshock') c.csplit##c.(`controls'), vce(rob)
global high "`mpshock' + c.csplit#c.`mpshock'"
global low "`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_csplit_`var'_)
quietly svmat alpha26, names(l_csplit_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
//
local variable tot_c_m
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_csplit_`var'_1 l_csplit_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(sand) lwidth(none)) ///
(rarea l_csplit_`var'_2 l_csplit_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(sand) lwidth(none)) ///
(connected l_csplit_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea h_csplit_`var'_1 h_csplit_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(maroon) lwidth(none)) ///
(rarea h_csplit_`var'_2 h_csplit_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(maroon) lwidth(none)) ///
(connected h_csplit_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "Pre 2008" 7 "Post 2008") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG8b.png, width(1000) height(1000) replace


/*============================================================*/
/*========================== Figure G9 =======================*/
/*============================================================*/

//------ FigG9a ------// 
cap drop h_*r2y* l_*r2y*
local cyclevar s
local statevar li_adj_ex_pti
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_ex_pti
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t} w/o `v2text'" 4 "Low S{subscript:t} w/o `v2text'") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on  // grc1leg
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.2) xsize(1) ysize(1) 
graph export FigG9a.png, width(1000) height(1000) replace
}
}


//------ FigG9b ------// 
cap drop c_pti_adj_95
tsfilter cf c_pti_adj_95 = pti_adj_95, minperiod(6) 
cap drop h_*mean* l_*mean*
local cyclevar c
local statevar pti_adj_95
local variable tot_c_m                            
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).pti
quiet reg `lead'.`var' L(0/1).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_mean_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_mean_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
}
local cyclevar c
local statevar pti_adj_95
local variable tot_c_m 
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_mean_`var'_1 h_`cyvar'_`stvar'_mean_`var'_5 xaxis, fcolor(sand) fintensity(40) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_mean_`var'_2 h_`cyvar'_`stvar'_mean_`var'_4 xaxis, fcolor(sand) fintensity(60) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_mean_`var'_3 xaxis, lcolor(sand) mcolor(sand) msymbol(circle) msize(large) mfcolor(sand)) ///
(rarea l_`cyvar'_`stvar'_mean_`var'_1 l_`cyvar'_`stvar'_mean_`var'_5 xaxis, fcolor(maroon) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_mean_`var'_2 l_`cyvar'_`stvar'_mean_`var'_4 xaxis, fcolor(maroon) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_mean_`var'_3 xaxis, lcolor(maroon) mcolor(maroon) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High PTI>p(95)" 7 "Low PTI>p(95)") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export FigG9b.png, width(1000) height(1000) replace
}
}

/*===========================================================*/
/*====================== Figure G10 =========================*/
/*===========================================================*/

//------ Detrended share of fitted values ------// 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar c6 c18
local statevar li_fit_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar c6 c18
local statevar li_fit_95
local variable tot_c_m
foreach stvar of local statevar {
foreach cyvar of local cyclevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(red) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(navy) fintensity(25) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(navy) fintensity(50) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(navy) mcolor(navy) msymbol(circle) msize(large) mfcolor(navy)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "High S{subscript:t}{superscript:d}" 7 "Low S{subscript:t}{superscript:d}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
}
}
set graphics on 
graph combine c6_li_fit_95_tot_c_m c18_li_fit_95_tot_c_m, ///
rows(1) cols(2) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.3) xsize(2) ysize(1) 
graph export FigG10.png, width(2000) height(1000) replace


/*=====================================================*/
/*========== Collapse for regional estimates  =========*/
/*=====================================================*/

collapse (mean) r_2y_shsum, by(yearq)
gen dateq = tq(2004q4) + _n-1
format %tq dateq
tsset dateq
save "RESTAT_MS24757_Agg_Macro_data.dta", replace


